package com.tensquare.article.controller;

import com.tensquare.article.service.ArticleService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Date 2021/3/21 14:58
 */
@RestController
@CrossOrigin
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;


    /***
     * 文章审核
     * Param: [label]
     **/
    @PutMapping("/examine/{articleId}")
    public Result examine(@PathVariable String articleId) {
        articleService.examine(articleId);
        return new Result(true, StatusCode.OK, "审核成功");
    }

    /***
     * 文章点赞
     * Param: [label]
     **/
    @PutMapping("/thumbup/{articleId}")
    public Result thumbup(@PathVariable String articleId) {
        articleService.thumbup(articleId);
        return new Result(true, StatusCode.OK, "点赞成功");
    }

    /***
     * 根据ID查询文章
     * Param: [articleId]
     **/
    @GetMapping("/{articleId}")
    public Result findById(@PathVariable String articleId) {
        return new Result(true, StatusCode.OK, "查询成功", articleService.findById(articleId));
    }

    /***
     * 根据id删除文章
     * Param: [articleId]
     **/
    @DeleteMapping("/{articleId}")
    public Result deleteById(@PathVariable String articleId) {
        articleService.deleteById(articleId);
        return new Result(true, StatusCode.OK, "删除成功");
    }
}
